/**
* @Description: WoShop商城
* @Author: 梧桐
* @Copyright: 武汉一一零七科技有限公司©版权所有
* @Link: www.wo-shop.net
* @Contact: QQ:2487937004
*/
<template>
	<view class="page">
		<view class="content">
			<!-- 未使用 -->
		 
				<view class="list" v-if="active==0">
					<view class="listItem" v-for="(item, index) in list" :key="index">
						<image :src="imgStaticUrl + '/images/coupon1.png'" class="coupon"></image>
						<view class="box">
							<view class="price">
								<view class="icon">{{$t('￥')}}</view>
								<view class="volum">{{ item.dec_price }}</view>
							</view>
							<view class="descripe">
								<view class="shop-name">{{item.shop_name}}</view>
								<view class="text">{{$t('满')}}{{$t('￥')}}{{ item.man_price }}{{$t('减')}}{{ item.dec_price }}</view>
								<view class="expire">{{ item.start_time }}-{{ item.end_time }}</view>
							</view>
							<view class="state" @click="getCoupon(item)">
								<text v-if="item.have == 0">{{$t('立即领取')}}</text>
								<image v-if="item.have == 1" :src="imgStaticUrl+'images/img/lingjuan.png'" mode="aspectFit"></image>
							</view>
						</view>
					</view>
					<view class="zhanwei"></view>
				</view>
				<div class="no-more" v-if="!isHas">{{$t('没有更多了')}}</div>
				
				<view class="button" @click="$u.route('/pagesB/coupon/coupon')">{{$t('我的券')}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgStaticUrl: this.STATICURL,
				tab: [this.$t('未使用'), this.$t('已使用'), this.$t('已过期')],
				active: 0, //当前选中项
				list: [],
				isHas: true,
				pageShow: false
			}
		},

		onLoad() {
			this.getcouponlst()
		},
		
		onPullDownRefresh(){
			this.getcouponlst()
		},

		// 切换
		methods: {

			getcouponlst() {
				// if (this.isMore) return

				this.$loading()

				this.$http.getcouponlst({
					type: 'all'
				}).then(res => {
					if (res.status === 200) {
						if (res.data.data.length) {
							this.list = res.data.data
							this.isHas = res.data.data.length
						} else {
							this.isHas = false
						}
					} else {
						this.$toast(res.mess)
					}
				})
			},
			
			getCoupon(item) {
				// 领取优惠券
				if (item.have == 0) {
					this.$loading()
					this.$http.getcoupons({
						coupon_id: item.id,
						shop_id: item.shop_id
					}).then(res => {
						if (res.status == 200) {
							this.$toast(res.mess)
							this.list.forEach((element, index) => {
								if (element.id == item.id) {
									element.have = 1
								}
							});
						}
					})
				}
			},
			
		}
		
		
	}
</script>

<style lang="less">
	.page {
		.button {
		    position: fixed;
			bottom: 80rpx;
			width: 500rpx;
		    height: 44px;
			left: 125rpx;
		    font-size: 16px;
		    background-image: -webkit-linear-gradient(left, #8bbefd, #e0e0e0);
		    background-image: linear-gradient(to right, #8bbefd, #e0e0e0);
			box-shadow: 4rpx 4rpx 4rpx #ccc;
			border-radius: 50rpx;
		}
		
		.navbar-right {
			// margin-right: 24rpx;
			display: flex;
			align-items: flex-end;
		}
		
		.right-item {
			margin: 0 12rpx;
			position: relative;
			color: #333;
			display: flex;
		}

		.content {

			.list {
				.listItem {
					padding: 11rpx 22rpx;
					background: #fff;
					position: relative;
					border-bottom: 1rpx solid #fbfbfb;

					&:last-child {
						border-bottom: none;
					}

					.coupon {
						width: 100%;
						height: 188rpx;
					}

					.box {
						color: #fff;
						position: absolute;
						left: 32rpx;
						top: 32rpx;
						right: 32rpx;
						bottom: 32rpx;
						padding: 42rpx 23rpx 42rpx 31rpx;
						display: flex;
						justify-content: space-around;
						align-items: center;

						.price {
							display: flex;
							justify-content: center;
							align-items: center;
							width: 120rpx;

							.icon {
								font-size: 36rpx;
							}

							.volum {
								font-size: 60rpx;
							}
						}

						.descripe {
							margin-left: 22rpx;
							flex: 1;
							
							.shop-name{
								background-color: #fff;
								color: #79b2fb;
								border-radius: 50rpx;
								padding: 2rpx 10rpx;
								width: fit-content;
								font-size: 24rpx;
							}

							.text {
								font-size: 24rpx;
								line-height: 33rpx;
								margin-top: 15rpx;
							}

							.expire {
								font-size: 18rpx;
								line-height: 25rpx;
								margin-top: 15rpx;

							}
						}

						.state {
							font-size: 28rpx;
							height: 120rpx;
							line-height: 120rpx;
							width: 120rpx;
							text-align: center;
							

							image {
								width: 121rpx;
								height: 121rpx;
								filter: grayscale(100%) brightness(400%);
							}
						}
					}
				}

			}
			
			.expired{
				.shop-name{
					color: #adacac!important;
				}
			}
		}
	}
	.zhanwei{
		height:220rpx;
	}
</style>
